/**
 * @Title: AlertUtils.java
 * @Copyright: XXX Co., Ltd. Copyright YYYY-YYYY,  All rights reserved
 * @Description: TODO<请描述此文件是做什么的>
 * @author: MeiYi
 * @data: 2016-5-18 下午1:50:01
 * @version: V1.0
 */

package artid.com.arttogoa.util;

import artid.com.arttogoa.R;
import artid.com.arttogoa.adapter.StrericWheelAdapter;
import artid.com.arttogoa.barcode.Bimp;
import artid.com.arttogoa.view.WheelView;

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.drawable.AnimationDrawable;
import android.net.Uri;
import android.support.v4.app.ActivityCompat;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.view.WindowManager.LayoutParams;
import android.view.animation.AnticipateOvershootInterpolator;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import static android.R.attr.title;
import static android.R.attr.width;

/**
 * TODO<请描述这个类是干什么的>
 *
 * @author 熊彬
 * @data: 2016-5-18 下午1:50:01
 * @version: V1.0
 */
@SuppressLint("CutPasteId")
public class AlertUtils {
	public static AlertDialog alertDialog;
	public static Dialog progressDialog;

	/**
	 * 取消弹窗
	 */
	public static void dismiss() {
		// TODO Auto-generated method stub
		if (AniDraw != null && AniDraw.isRunning()) {
			AniDraw.stop();
			AniDraw = null;
		}
		if (alertDialog != null && alertDialog.isShowing()) {
			alertDialog.dismiss();
			alertDialog = null;
		}
	}

	public static void disMissLoding() {
		if (AniDraw != null && AniDraw.isRunning()) {
			AniDraw.stop();
			AniDraw = null;
		}
		if (progressDialog != null && progressDialog.isShowing()) {
			progressDialog.dismiss();
			progressDialog = null;
		}
	}

	private static AnimationDrawable AniDraw;

	public static void showLoding(Context activity) {
		if (progressDialog == null) {
			LayoutInflater inflater = LayoutInflater.from(activity);
			View v = inflater.inflate(R.layout.loading, null);// 得到加载view
			RelativeLayout layout = (RelativeLayout) v
					.findViewById(R.id.rel_dialog);// 加载布局
			ImageView fireImg = (ImageView) v.findViewById(R.id.iv);
			AniDraw = (AnimationDrawable) fireImg.getBackground();
			AniDraw.start();
			progressDialog = new Dialog(activity, R.style.dialog);// 创建自定义样式dialog
			progressDialog.setCancelable(false);// 不可以用“返回键”取消
			progressDialog.setContentView(layout,
					new LinearLayout.LayoutParams(
							LinearLayout.LayoutParams.FILL_PARENT,
							LinearLayout.LayoutParams.FILL_PARENT));// 设置布局
		}
		if (!progressDialog.isShowing()) {
			progressDialog.show();
		}
	}

	/**
	 * 有文字提示进度条
	 */
	@SuppressLint("InflateParams")
	public static AlertDialog initloadAlertDialog(final Context mContext,
												  int width, String content) {
		View view = LayoutInflater.from(mContext).inflate(
				R.layout.pop_menu_upload, null);
		pb = (ProgressBar) view.findViewById(R.id.upload_progress);
		contentView = (TextView) view.findViewById(R.id.tv_phone);
		contentView.setText(content);
		ImageView fireImg = (ImageView) view.findViewById(R.id.iv);
		AniDraw = (AnimationDrawable) fireImg.getDrawable();
		AniDraw.start();
		fireImg.setVisibility(View.VISIBLE);
		pb.setVisibility(View.GONE);
		// if (TextUtils.isEmpty(content)) {
		// contentView.setVisibility(View.GONE);
		// } else {
		// contentView.setText(content);
		// }
		alertDialog = new AlertDialog.Builder(mContext).create();
		// final AnimationDrawable animDrawable =
		// (AnimationDrawable)fireImg.getBackground();
		// fireImg.post(new Runnable() {
		// @Override
		// public void run() {
		// animDrawable.start();
		// }
		// });
		alertDialog.setCancelable(false);
		alertDialog.show();

		WindowManager.LayoutParams params = alertDialog.getWindow()
				.getAttributes();
		params.width = width * 4 / 5;

		params.height = LayoutParams.WRAP_CONTENT;
		params.gravity = Gravity.CENTER;

		Window window = alertDialog.getWindow();
		window.setAttributes(params);
		window.setContentView(view);
		alertDialog.getWindow().setContentView(view);
		return alertDialog;
	}

	/**
	 * 大图片取微观图提示框
	 */
	@SuppressLint("NewApi")
	public static AlertDialog initMicmapAlertDialog(final Context mContext,
													int width, OnClickListener onClick) {
		View view = LayoutInflater.from(mContext).inflate(
				R.layout.pop_menu_micmap, null);

		view.findViewById(R.id.tv_determine).setOnClickListener(onClick);
		view.findViewById(R.id.tv_cancel).setOnClickListener(onClick);

		alertDialog = new AlertDialog.Builder(mContext, R.style.dialog123)
				.create();
		alertDialog.show();
		WindowManager.LayoutParams params = alertDialog.getWindow()
				.getAttributes();
		params.width = width;

		params.height = LayoutParams.WRAP_CONTENT;
		params.gravity = Gravity.BOTTOM;

		Window window = alertDialog.getWindow();
		window.setAttributes(params);
		window.setContentView(view);
		alertDialog.getWindow().setContentView(view);
		return alertDialog;
	}

	/**
	 * 选择图片对话框
	 */
	public static AlertDialog initPhotoAlertDialog(final Context mContext,
												   int width, OnClickListener onClick) {
		View view = LayoutInflater.from(mContext).inflate(
				R.layout.pop_menu_photo, null);

		view.findViewById(R.id.tv_phone).setOnClickListener(onClick);
		view.findViewById(R.id.tv_choice).setOnClickListener(onClick);
		view.findViewById(R.id.tv_cancel).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						dismiss();
					}
				});

		alertDialog = new AlertDialog.Builder(mContext).create();
		alertDialog.show();
		WindowManager.LayoutParams params = alertDialog.getWindow()
				.getAttributes();
		params.width = width;

		params.height = LayoutParams.WRAP_CONTENT;
		params.gravity = Gravity.BOTTOM;

		Window window = alertDialog.getWindow();
		window.setAttributes(params);
		window.setContentView(view);
		alertDialog.getWindow().setContentView(view);
		return alertDialog;
	}

	/**
	 * 备案选择图片对话框
	 */
	public static AlertDialog initFilingPhotoAlertDialog(
			final Context mContext, int width, OnClickListener onClick,
			int pictureLimit) {
		View view = LayoutInflater.from(mContext).inflate(
				R.layout.pop_menu_filingphoto, null);

		view.findViewById(R.id.tv_phone).setOnClickListener(onClick);
		view.findViewById(R.id.tv_choice).setOnClickListener(onClick);
		view.findViewById(R.id.tv_diver).setOnClickListener(onClick);
		if (pictureLimit == 1) {
			view.findViewById(R.id.tv_diver).setVisibility(View.GONE);
		} else if (pictureLimit == 2) {
			view.findViewById(R.id.tv_choice).setVisibility(View.GONE);
			view.findViewById(R.id.tv_phone).setVisibility(View.GONE);
		}

		view.findViewById(R.id.tv_cancel).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						dismiss();
					}
				});

		alertDialog = new AlertDialog.Builder(mContext).create();
		alertDialog.show();
		WindowManager.LayoutParams params = alertDialog.getWindow()
				.getAttributes();
		params.width = width;

		params.height = LayoutParams.WRAP_CONTENT;
		params.gravity = Gravity.BOTTOM;

		Window window = alertDialog.getWindow();
		window.setAttributes(params);
		window.setContentView(view);
		alertDialog.getWindow().setContentView(view);
		return alertDialog;
	}

	/**
	 * 选择资讯类别
	 */
	public static AlertDialog initCateAlertDialog(final Context mContext,
												  int width, OnClickListener onClick) {
		View view = LayoutInflater.from(mContext).inflate(
				R.layout.pop_menu_cate, null);

		view.findViewById(R.id.tv_yspzx).setOnClickListener(onClick);
		view.findViewById(R.id.tv_zhzx).setOnClickListener(onClick);
		view.findViewById(R.id.tv_pmzx).setOnClickListener(onClick);
		view.findViewById(R.id.tv_hlzx).setOnClickListener(onClick);
		view.findViewById(R.id.tv_cancel).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						dismiss();
					}
				});

		alertDialog = new AlertDialog.Builder(mContext).create();
		alertDialog.show();
		WindowManager.LayoutParams params = alertDialog.getWindow()
				.getAttributes();
		params.width = width;

		params.height = LayoutParams.WRAP_CONTENT;
		params.gravity = Gravity.BOTTOM;

		Window window = alertDialog.getWindow();
		window.setAttributes(params);
		window.setContentView(view);
		alertDialog.getWindow().setContentView(view);
		return alertDialog;
	}

	/**
	 * 显示资讯发布须知
	 */
	public static AlertDialog showConsultaDialog(final Context mContext,
												 int width, OnClickListener onClick) {
		View view = LayoutInflater.from(mContext).inflate(
				R.layout.pop_menu_consintro, null);

		view.findViewById(R.id.imageView2).setOnClickListener(onClick);

		alertDialog = new AlertDialog.Builder(mContext).create();
		alertDialog.show();
		WindowManager.LayoutParams params = alertDialog.getWindow()
				.getAttributes();
		params.width = width;
		params.height = LayoutParams.WRAP_CONTENT;
		Window window = alertDialog.getWindow();
		window.setAttributes(params);
		window.setContentView(view);
		alertDialog.getWindow().setContentView(view);
		return alertDialog;
	}

	/**
	 * 编辑完整图对话框
	 */
	@SuppressLint("InflateParams")
	public static AlertDialog initEditAlertDialog(final Context mContext,
												  int width, OnClickListener onClick) {
		View view = LayoutInflater.from(mContext).inflate(
				R.layout.pop_menu_edit, null);

		view.findViewById(R.id.tv_ok).setOnClickListener(onClick);
		view.findViewById(R.id.tv_no).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						dismiss();
					}
				});
		alertDialog = new AlertDialog.Builder(mContext).create();
		alertDialog.show();
		WindowManager.LayoutParams params = alertDialog.getWindow()
				.getAttributes();
		params.width = width * 4 / 5;

		params.height = LayoutParams.WRAP_CONTENT;
		params.gravity = Gravity.CENTER;

		Window window = alertDialog.getWindow();
		window.setAttributes(params);
		window.setContentView(view);
		alertDialog.getWindow().setContentView(view);
		return alertDialog;
	}

	private static TextView contentView;

	private static ProgressBar pb;
	private static ImageView artInfo;

	public static void setProgressBar(int s) {
		if (pb != null)
			pb.setProgress(s);
	}

	public static void setUploadImage(boolean status) {

		if (pb != null)
			pb.setVisibility(View.GONE);
		if (fireIg != null)
			fireIg.setVisibility(View.GONE);
		if (artInfo != null && contentView != null) {
			artInfo.setVisibility(View.VISIBLE);

			if (status) {
				artInfo.setImageResource(R.drawable.yspba_ico_success);
				contentView.setText("认证申请已提交，请等待审核！");
			} else {
				artInfo.setImageResource(R.drawable.yspba_ico_wrong);
				contentView.setText("上传备案失败");
			}
		}
	}

	public static void setGoodsImage(boolean status, int goodstype) {

		if (pb != null)
			pb.setVisibility(View.GONE);
		else {

		}
		if (artInfo != null && contentView != null) {
			artInfo.setVisibility(View.VISIBLE);
			String info = (goodstype == Bimp.GOODS_PUBLISH) ? "发布商品" : "编辑商品";

			if (status) {
				artInfo.setImageResource(R.drawable.yspba_ico_success);
				contentView.setText(info + (status ? "成功" : "失败"));
			} else {
				artInfo.setImageResource(R.drawable.yspba_ico_wrong);
				contentView.setText(info + (status ? "成功" : "失败"));
			}
		}
	}

	static ImageView fireIg;

	/**
	 * 上传备案对话框
	 */
	@SuppressLint("InflateParams")
	public static AlertDialog initUploadAlertDialog2(final Context mContext,
													 int width, String content) {
		View view = LayoutInflater.from(mContext).inflate(
				R.layout.pop_menu_load, null);
		pb = (ProgressBar) view.findViewById(R.id.upload_progress);
		artInfo = (ImageView) view.findViewById(R.id.iv_artinfo);
		contentView = (TextView) view.findViewById(R.id.tv_phone);
		pb.setVisibility(View.GONE);
		contentView.setText(content);
		fireIg = (ImageView) view.findViewById(R.id.iv);
		fireIg.setVisibility(View.VISIBLE);
		fireIg.setVisibility(View.VISIBLE);
		AniDraw = (AnimationDrawable) fireIg.getDrawable();
		AniDraw.start();
		alertDialog = new AlertDialog.Builder(mContext).create();
		// final AnimationDrawable animDrawable =
		// (AnimationDrawable)fireImg.getBackground();
		// fireImg.post(new Runnable() {
		// @Override
		// public void run() {
		// animDrawable.start();
		// }
		// });
		alertDialog.setCancelable(false);
		alertDialog.show();

		WindowManager.LayoutParams params = alertDialog.getWindow()
				.getAttributes();
		params.width = width * 4 / 5;

		params.height = LayoutParams.WRAP_CONTENT;
		params.gravity = Gravity.CENTER;

		Window window = alertDialog.getWindow();
		window.setAttributes(params);
		window.setContentView(view);
		alertDialog.getWindow().setContentView(view);
		return alertDialog;
	}

	/**
	 * 上传备案对话框
	 */
	@SuppressLint("InflateParams")
	public static AlertDialog initUploadAlertDialog(final Context mContext,
													int width, String content) {
		View view = LayoutInflater.from(mContext).inflate(
				R.layout.pop_menu_load, null);
		pb = (ProgressBar) view.findViewById(R.id.upload_progress);
		artInfo = (ImageView) view.findViewById(R.id.iv_artinfo);
		contentView = (TextView) view.findViewById(R.id.tv_phone);
		pb.setVisibility(View.VISIBLE);
		contentView.setText(content);
		alertDialog = new AlertDialog.Builder(mContext).create();
		// final AnimationDrawable animDrawable =
		// (AnimationDrawable)fireImg.getBackground();
		// fireImg.post(new Runnable() {
		// @Override
		// public void run() {
		// animDrawable.start();
		// }
		// });
		alertDialog.setCancelable(false);
		alertDialog.show();

		WindowManager.LayoutParams params = alertDialog.getWindow()
				.getAttributes();
		params.width = width * 4 / 5;

		params.height = LayoutParams.WRAP_CONTENT;
		params.gravity = Gravity.CENTER;

		Window window = alertDialog.getWindow();
		window.setAttributes(params);
		window.setContentView(view);
		alertDialog.getWindow().setContentView(view);
		return alertDialog;
	}

	/**
	 * 判断是否是外网
	 */
	@SuppressLint("InflateParams")
	public static AlertDialog initJudgeOutsideAlertDialog(
			final Activity mContext) {
		View view = LayoutInflater.from(mContext).inflate(
				R.layout.pop_menu_upload, null);
		contentView = (TextView) view.findViewById(R.id.tv_phone);
		TextView ok = (TextView) view.findViewById(R.id.tv_ok);
		ImageView pro = (ImageView) view.findViewById(R.id.iv);
		contentView.setText("您还没有连接外网，\n去连接网络完成请求！");
		pro.setVisibility(View.GONE);
		ok.setVisibility(View.VISIBLE);
		ok.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				// Intent intent = null;
				// // 先判断当前系统版本
				// if (android.os.Build.VERSION.SDK_INT > 10) { // 3.0以上
				// intent = new Intent(
				// android.provider.Settings.ACTION_WIRELESS_SETTINGS);
				// } else {
				// intent = new Intent();
				// intent.setClassName("com.android.settings",
				// "com.android.settings.WirelessSettings");
				// }
				// mContext.startActivity(intent);
				if (android.os.Build.VERSION.SDK_INT > 10) {
					// 3.0以上打开设置界面，也可以直接用ACTION_WIRELESS_SETTINGS打开到wifi界面
					mContext.startActivity(new Intent(
							android.provider.Settings.ACTION_WIFI_SETTINGS));
				} else {
					mContext.startActivity(new Intent(
							android.provider.Settings.ACTION_WIFI_SETTINGS));
				}
				dismiss();
			}
		});
		alertDialog = new AlertDialog.Builder(mContext).create();
		alertDialog.setCancelable(false);
		alertDialog.show();
		WindowManager.LayoutParams params = alertDialog.getWindow()
				.getAttributes();
		params.width = Integer.parseInt(NetUtils.getDisplayMetrics(mContext)
				.get(NetUtils.DM_WIDTH)) * 4 / 5;

		params.height = LayoutParams.WRAP_CONTENT;
		params.gravity = Gravity.CENTER;

		Window window = alertDialog.getWindow();
		window.setAttributes(params);
		window.setContentView(view);
		alertDialog.getWindow().setContentView(view);
		return alertDialog;
	}

	/**
	 * 判断是否是外网
	 */
	@SuppressLint("InflateParams")
	public static AlertDialog initSubmitSumAlertDialog(final Activity mContext,
													   String con) {
		View view = LayoutInflater.from(mContext).inflate(
				R.layout.pop_menu_upload, null);
		contentView = (TextView) view.findViewById(R.id.tv_phone);
		TextView ok = (TextView) view.findViewById(R.id.tv_ok);
		ImageView pro = (ImageView) view.findViewById(R.id.iv);
		contentView.setText(con);
		pro.setVisibility(View.GONE);
		ok.setVisibility(View.VISIBLE);
		ok.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				dismiss();
			}
		});
		alertDialog = new AlertDialog.Builder(mContext).create();
		alertDialog.setCancelable(false);
		alertDialog.show();
		WindowManager.LayoutParams params = alertDialog.getWindow()
				.getAttributes();
		params.width = Integer.parseInt(NetUtils.getDisplayMetrics(mContext)
				.get(NetUtils.DM_WIDTH)) * 4 / 5;

		params.height = LayoutParams.WRAP_CONTENT;
		params.gravity = Gravity.CENTER;

		Window window = alertDialog.getWindow();
		window.setAttributes(params);
		window.setContentView(view);
		alertDialog.getWindow().setContentView(view);
		return alertDialog;
	}

	public static void setText(String content) {
		if (contentView != null) {
			contentView.setText(content);
		}
	}

	/**
	 * 消息对话框
	 */
	@SuppressLint("InflateParams")
	public static AlertDialog MessageAlertDialog(final Context mContext,
												 String title, int width, OnClickListener onClick) {
		View view = LayoutInflater.from(mContext).inflate(
				R.layout.pop_menu_edit, null);
		TextView title_tv = (TextView) view.findViewById(R.id.tv_phone);
		title_tv.setText(title);
		view.findViewById(R.id.tv_ok).setOnClickListener(onClick);
		view.findViewById(R.id.tv_no).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						dismiss();
					}
				});
		alertDialog = new AlertDialog.Builder(mContext).create();
		alertDialog.show();
		WindowManager.LayoutParams params = alertDialog.getWindow()
				.getAttributes();
		params.width = width * 4 / 5;

		params.height = LayoutParams.WRAP_CONTENT;
		params.gravity = Gravity.CENTER;

		Window window = alertDialog.getWindow();
		window.setAttributes(params);
		window.setContentView(view);
		alertDialog.getWindow().setContentView(view);
		return alertDialog;
	}

	/**
	 * 一个按钮的对话框
	 */
	@SuppressLint("InflateParams")
	public static AlertDialog OneButtonAlertDialog(final Context mContext,
												   String Content, String ButtonName, int ButtonColor, int width,
												   OnClickListener onClick) {
		View view = LayoutInflater.from(mContext).inflate(
				R.layout.pop_menu_onebutton, null);
		TextView title_tv = (TextView) view.findViewById(R.id.tv_content);
		title_tv.setText(Content);
		TextView button = (TextView) view.findViewById(R.id.tv_ok);
		button.setOnClickListener(onClick);
		button.setText(ButtonName);
		button.setTextColor(ButtonColor);
		alertDialog = new AlertDialog.Builder(mContext).create();
		alertDialog.show();
		WindowManager.LayoutParams params = alertDialog.getWindow()
				.getAttributes();
		params.width = width * 4 / 5;

		params.height = LayoutParams.WRAP_CONTENT;
		params.gravity = Gravity.CENTER;

		Window window = alertDialog.getWindow();
		window.setAttributes(params);
		window.setContentView(view);
		alertDialog.getWindow().setContentView(view);
		return alertDialog;
	}

	/**
	 * 三个列表形式的对话框(类似于上传图片选择对话框)
	 */
	public static AlertDialog threeTextViewAlertDialog(final Context mContext,
													   int width, String oneTextView, String twoTextView,
													   OnClickListener onClick) {
		View view = LayoutInflater.from(mContext).inflate(
				R.layout.pop_filingsell, null);

		TextView tv_phone = (TextView) view
				.findViewById(R.id.pop_filingsell_FilingQuickSell);
		tv_phone.setOnClickListener(onClick);
		tv_phone.setText(oneTextView);
		TextView tv_choice = (TextView) view
				.findViewById(R.id.pop_filingsell_CameraSell);
		tv_choice.setOnClickListener(onClick);
		tv_choice.setText(twoTextView);
		TextView tv_cancel = (TextView) view
				.findViewById(R.id.pop_filingsell_cancel);
		tv_cancel.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				dismiss();
			}
		});

		alertDialog = new AlertDialog.Builder(mContext).create();
		alertDialog.show();
		WindowManager.LayoutParams params = alertDialog.getWindow()
				.getAttributes();
		params.width = width;

		params.height = LayoutParams.WRAP_CONTENT;
		params.gravity = Gravity.BOTTOM;

		Window window = alertDialog.getWindow();
		window.setAttributes(params);
		window.setContentView(view);
		alertDialog.getWindow().setContentView(view);
		return alertDialog;
	}

	public static String pId = "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35";
	public static String[] pids = pId.split(",");
	public static String PName = "北京,天津,河北,山西,内蒙古,辽宁,吉林,黑龙江,上海,江苏,浙江,安徽,福建,江西,山东,河南,湖北,湖南,广东,广西,海南,重庆,四川,贵州,云南,西藏,陕西,甘肃,青海,宁夏,新疆,台湾,香港,澳门,海外";
	public static String[] pnames = PName.split(",");
	// 通过市找到省
	public static String CtoP = "1,9,2,22,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,13,14,14,14,14,14,14,14,14,14,14,14,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,18,18,18,18,18,18,18,18,18,18,18,18,18,18,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,20,20,20,20,20,20,20,20,20,20,20,20,20,20,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,24,24,24,24,24,24,24,24,24,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,26,26,26,26,26,26,26,27,27,27,27,27,27,27,27,27,27,28,28,28,28,28,28,28,28,28,28,28,28,28,28,29,29,29,29,29,29,29,29,30,30,30,30,30,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,34,35";
	public static String[] cpids = CtoP.split(",");
	public static String CName = "北京市,上海市,天津市,重庆市,石家庄市,唐山市,秦皇岛市,邯郸市,邢台市,保定市,张家口市,承德市,衡水市,廊坊市,沧州市,太原市,大同市,阳泉市,长治市,晋城市,朔州市,晋中市,运城市,忻州市,临汾市,吕梁市,呼和浩特市,包头市,乌海市,赤峰市,通辽市,鄂尔多斯市,呼伦贝尔市,巴彦淖尔市,乌兰察布市,兴安盟,锡林郭勒盟,阿拉善盟,沈阳市,大连市,鞍山市,抚顺市,本溪市,丹东市,锦州市,营口市,阜新市,辽阳市,盘锦市,铁岭市,朝阳市,葫芦岛市,长春市,吉林市,四平市,辽源市,通化市,白山市,松原市,白城市,延边朝鲜族自治州,哈尔滨市,齐齐哈尔市,鸡西市,鹤岗市,双鸭山市,大庆市,伊春市,佳木斯市,七台河市,牡丹江市,黑河市,绥化市,大兴安岭地区,南京市,无锡市,徐州市,常州市,苏州市,南通市,连云港市,淮安市,盐城市,扬州市,镇江市,泰州市,宿迁市,杭州市,宁波市,温州市,嘉兴市,湖州市,绍兴市,舟山市,衢州市,金华市,台州市,丽水市,合肥市,芜湖市,蚌埠市,淮南市,马鞍山市,淮北市,铜陵市,安庆市,黄山市,滁州市,阜阳市,宿州市,巢湖市,六安市,亳州市,池州市,宣城市,福州市,厦门市,莆田市,三明市,泉州市,漳州市,南平市,龙岩市,宁德市,南昌市,景德镇市,萍乡市,九江市,新余市,鹰潭市,赣州市,吉安市,宜春市,抚州市,上饶市,济南市,青岛市,淄博市,枣庄市,东营市,烟台市,潍坊市,济宁市,泰安市,威海市,日照市,莱芜市,临沂市,德州市,聊城市,滨州市,菏泽市,郑州市,开封市,洛阳市,平顶山市,安阳市,鹤壁市,新乡市,焦作市,濮阳市,许昌市,漯河市,三门峡市,南阳市,商丘市,信阳市,周口市,驻马店市,济源市,武汉市,黄石市,十堰市,宜昌市,襄樊市,鄂州市,荆门市,孝感市,荆州市,黄冈市,咸宁市,随州市,恩施土家族苗族自治州,仙桃市,潜江市,天门市,神农架林区,长沙市,株洲市,湘潭市,衡阳市,邵阳市,岳阳市,常德市,张家界市,益阳市,郴州市,永州市,怀化市,娄底市,湘西土家族苗族自治州,广州市,韶关市,深圳市,珠海市,汕头市,佛山市,江门市,湛江市,茂名市,肇庆市,惠州市,梅州市,汕尾市,河源市,阳江市,清远市,东莞市,中山市,潮州市,揭阳市,云浮市,南宁市,柳州市,桂林市,梧州市,北海市,防城港市,钦州市,贵港市,玉林市,百色市,贺州市,河池市,来宾市,崇左市,海口市,三亚市,五指山市,琼海市,儋州市,文昌市,万宁市,东方市,定安县,屯昌县,澄迈县,临高县,白沙黎族自治县,昌江黎族自治县,乐东黎族自治县,陵水黎族自治县,保亭黎族苗族自治县,琼中黎族苗族自治县,西沙群岛,南沙群岛,中沙群岛的岛礁及其海域,成都市,自贡市,攀枝花市,泸州市,德阳市,绵阳市,广元市,遂宁市,内江市,乐山市,南充市,眉山市,宜宾市,广安市,达州市,雅安市,巴中市,资阳市,阿坝藏族羌族自治州,甘孜藏族自治州,凉山彝族自治州,贵阳市,六盘水市,遵义市,安顺市,铜仁地区,黔西南布依族苗族自治州,毕节地区,黔东南苗族侗族自治州,黔南布依族苗族自治州,昆明市,曲靖市,玉溪市,保山市,昭通市,丽江市,思茅市,临沧市,楚雄彝族自治州,红河哈尼族彝族自治州,文山壮族苗族自治州,西双版纳傣族自治州,大理白族自治州,德宏傣族景颇族自治州,怒江傈僳族自治州,迪庆藏族自治州,拉萨市,昌都地区,山南地区,日喀则地区,那曲地区,阿里地区,林芝地区,西安市,铜川市,宝鸡市,咸阳市,渭南市,延安市,汉中市,榆林市,安康市,商洛市,兰州市,嘉峪关市,金昌市,白银市,天水市,武威市,张掖市,平凉市,酒泉市,庆阳市,定西市,陇南市,临夏回族自治州,甘南藏族自治州,西宁市,海东地区,海北藏族自治州,黄南藏族自治州,海南藏族自治州,果洛藏族自治州,玉树藏族自治州,海西蒙古族藏族自治州,银川市,石嘴山市,吴忠市,固原市,中卫市,乌鲁木齐市,克拉玛依市,吐鲁番地区,哈密地区,昌吉回族自治州,博尔塔拉蒙古自治州,巴音郭楞蒙古自治州,阿克苏地区,克孜勒苏柯尔克孜自治州,喀什地区,和田地区,伊犁哈萨克自治州,塔城地区,阿勒泰地区,石河子市,阿拉尔市,图木舒克市,五家渠市,台北市,高雄市,基隆市,台中市,台南市,新竹市,嘉义市,台北县,宜兰县,桃园县,新竹县,苗栗县,台中县,彰化县,南投县,云林县,嘉义县,台南县,高雄县,屏东县,澎湖县,台东县,花莲县,中西区,东区,九龙城区,观塘区,南区,深水埗区,黄大仙区,湾仔区,油尖旺区,离岛区,葵青区,北区,西贡区,沙田区,屯门区,大埔区,荃湾区,元朗区,澳门特别行政区,海外";
	public static String[] cnames = CName.split(",");
	public static String Cid = "36,39,40,62,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320,321,322,323,324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,341,342,343,344,385,386,387,388,389,390,391,392,393,394,395,396,397,398,399,400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,419,420,421,422,423,424,425,426,427,428,429,430,431,432,433,434,435,436,437,438,439,440,441,442,443,444,445,446,447,448,449,450,451,452,453,454,455,456,457,458,459,460,461,462,463,464,465,466,467,468,469,470,471,472,473,474,475,476,477,478,479,480,481,482,483,484,485,486,487,488,489,490,491,492,493,494,495,496,497,498,499,500,501,502,503,504,505,506,507,508,509,510,511,512,513,514,515,516,517,518,519,520,521,522,523,524,525,526,527,528,529,530,531,532,533,534,45055";
	public static String[] cids = Cid.split(",");
	public static int selectP = 0;
	public static int selectC = 0;
	public static String[] cids_Selected;

	public static AlertDialog CityDialog(Context mContext, int width,
										 OnClickListener onClick) {
		View view = LayoutInflater.from(mContext).inflate(
				R.layout.pop_second_level, null);
		WheelView wheelView1 = (WheelView) view
				.findViewById(R.id.pop_second_level_wheelView1);
		final WheelView wheelView2 = (WheelView) view
				.findViewById(R.id.pop_second_level_wheelView2);
		Button btnCancel = (Button) view
				.findViewById(R.id.pop_second_level_btnCancel);
		Button btnConfirm = (Button) view
				.findViewById(R.id.pop_second_level_btnConfirm);
		wheelView1.setAdapter(new StrericWheelAdapter(pnames));
		wheelView1.setCurrentItem(0);
		wheelView1.setCyclic(true);
		wheelView1.setInterpolator(new AnticipateOvershootInterpolator());
		wheelView1.addChangingListener(new OnWheelChangedListener() {

			@Override
			public void onChanged(WheelView wheel, int oldValue, int newValue) {
				// TODO Auto-generated method stub
				wheelView2.setAdapter(new StrericWheelAdapter(
						getCitys(newValue)));
				wheelView2.setCurrentItem(0);
				selectP = newValue;
			}
		});
		wheelView2.setAdapter(new StrericWheelAdapter(getCitys(wheelView1
				.getCurrentItem())));
		wheelView2.setCurrentItem(0);
		wheelView2.addChangingListener(new OnWheelChangedListener() {

			@Override
			public void onChanged(WheelView wheel, int oldValue, int newValue) {
				// TODO Auto-generated method stub
				selectC = newValue;
			}
		});
		btnCancel.setOnClickListener(onClick);
		btnConfirm.setOnClickListener(onClick);
		alertDialog = new AlertDialog.Builder(mContext).create();
		alertDialog.show();
		WindowManager.LayoutParams params = alertDialog.getWindow()
				.getAttributes();
		params.width = width;

		params.height = LayoutParams.WRAP_CONTENT;
		params.gravity = Gravity.BOTTOM;

		Window window = alertDialog.getWindow();
		window.setAttributes(params);
		window.setContentView(view);
		alertDialog.getWindow().setContentView(view);
		return alertDialog;
	}

	static String[] getCitys(int PIndex) {
		String strall = "";
		String pid = pids[PIndex];
		String cidall = "";
		// 找出对应城市id所在的index
		for (int i = 0; i < cpids.length; i++) {
			String pcid = cpids[i];
			if (pcid.equals(pid)) {
				strall += cnames[i] + ",";
				cidall += cids[i] + ",";
			}
		}
		cids_Selected = cidall.split(",");
		return strall.split(",");
	}

	public static String getPid() {
		return pids[selectP];
	}

	public static String getCid() {
		return cids_Selected[selectC];
	}

	public static String getCityName() {
		return getCitys(selectP)[selectC];
	}

	public static String getProvName() {
		return pnames[selectP];
	}

	/**
	 * 删除确定对话框
	 */
	@SuppressLint("InflateParams")
	public static AlertDialog deleteDialog(final Context mContext,
										   String title, int width, OnClickListener onClick) {
		View view = LayoutInflater.from(mContext).inflate(R.layout.pop_delete,
				null);
		TextView title_tv = (TextView) view.findViewById(R.id.tv_title);
		title_tv.setText(title);
		TextView determine_tv = (TextView) view.findViewById(R.id.tv_determine);
		determine_tv.setOnClickListener(onClick);
		TextView cancel_tv = (TextView) view.findViewById(R.id.tv_cancel);
		cancel_tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				AlertUtils.dismiss();
			}
		});
		alertDialog = new AlertDialog.Builder(mContext).create();
		alertDialog.show();
		WindowManager.LayoutParams params = alertDialog.getWindow()
				.getAttributes();
		params.width = width;
		params.height = LayoutParams.WRAP_CONTENT;
		params.gravity = Gravity.BOTTOM;

		Window window = alertDialog.getWindow();
		window.setAttributes(params);
		window.setContentView(view);
		alertDialog.getWindow().setContentView(view);
		return alertDialog;
	}

	/**
	 * 俩按钮一个提示的选择框
	 */
	@SuppressLint("InflateParams")
	public static AlertDialog AlertTwoBtnDialog(final Context mContext,
												String title, String leftBtnName, String rightBtnName, int width,
												OnClickListener onClick) {
		View view = LayoutInflater.from(mContext).inflate(
				R.layout.pop_menu_edit, null);
		TextView title_tv = (TextView) view.findViewById(R.id.tv_phone);
		title_tv.setText(title);
		TextView leftBtn = (TextView) view.findViewById(R.id.tv_ok);
		leftBtn.setText(leftBtnName);
		TextView rightBtn = (TextView) view.findViewById(R.id.tv_no);
		rightBtn.setText(rightBtnName);
		leftBtn.setOnClickListener(onClick);
		rightBtn.setOnClickListener(onClick);
		alertDialog = new AlertDialog.Builder(mContext).create();
		alertDialog.show();
		WindowManager.LayoutParams params = alertDialog.getWindow()
				.getAttributes();
		params.width = width * 4 / 5;

		params.height = LayoutParams.WRAP_CONTENT;
		params.gravity = Gravity.CENTER;

		Window window = alertDialog.getWindow();
		window.setAttributes(params);
		window.setContentView(view);
		alertDialog.getWindow().setContentView(view);
		return alertDialog;
	}

	/**
	 * 电子签名确认对话框
	 */
	@SuppressLint("InflateParams")
	public static AlertDialog AlertElectronicSignatureDialog(
			final Context mContext, Bitmap mBitmap, int width,
			OnClickListener onClick) {
		View view = LayoutInflater.from(mContext).inflate(
				R.layout.pop_menu_electronicsignature, null);
		ImageView mImageView = (ImageView) view
				.findViewById(R.id.pop_menu_electronicsignature_img);
		mImageView.setImageBitmap(mBitmap);
		TextView resetBtn = (TextView) view
				.findViewById(R.id.pop_menu_electronicsignature_resetBtn);
		TextView saveBtn = (TextView) view
				.findViewById(R.id.pop_menu_electronicsignature_saveBtn);
		resetBtn.setOnClickListener(onClick);
		saveBtn.setOnClickListener(onClick);
		alertDialog = new AlertDialog.Builder(mContext).create();
		alertDialog.show();
		WindowManager.LayoutParams params = alertDialog.getWindow()
				.getAttributes();
		params.width = width;

		params.height = LayoutParams.WRAP_CONTENT;
		params.gravity = Gravity.CENTER;

		Window window = alertDialog.getWindow();
		window.setAttributes(params);
		window.setContentView(view);
		alertDialog.getWindow().setContentView(view);
		return alertDialog;
	}


	/**
	 * 拨打电话
	 */
	@SuppressLint("InflateParams")
	public static void MakePhoneDialog(final Context mContext,String title, String phoneNum, int width) {
		if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
			AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
			builder.setTitle(mContext.getString(R.string.app_name));
			builder.setMessage("请开启拨打电话的权限");
			builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					NetUtils.getAppDetailSettingIntent(mContext);
				}
			});
			builder.show();
			return;
		}
		AlertUtils.AlertTwoBtnDialog(mContext, title+"\n\n" + phoneNum, "确定", "取消", width, new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				switch (v.getId()) {
					case R.id.tv_ok:
						// 用intent启动拨打电话
						Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + "010-64688820"));
						mContext.startActivity(intent);
						AlertUtils.dismiss();
						break;
					case R.id.tv_no:
						AlertUtils.dismiss();
						break;
					default:
						break;
				}
			}
		});
	}
}
